package com.lmco.ws101.tipcalc;

import java.math.BigDecimal;
import java.math.BigInteger;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(name = "CalculateTipInterface", targetNamespace = "http://ws101.lmco.com/tipcalc")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class CalculateTipImpl implements CalculateTipInterface {

    @Override
    public CalculateTipResponse calculateTip(CalculateTipRequest body) {
	ObjectFactory factory = new ObjectFactory();
	CalculateTipResponse response = factory.createCalculateTipResponse();
	
	BigDecimal billAmount = BigDecimal.ZERO;
	if (body.getBillAmount() != null) {
	    billAmount = body.getBillAmount();
	}
	
	if ("GOOD".equals(body.getServiceLevel())) {
	    response.setTipPercent(BigInteger.valueOf(20));
	    response.setTipAmount(BigDecimal.valueOf(0.20).multiply(billAmount));
	} else if ("BAD".equals(body.getServiceLevel())) {
	    response.setTipPercent(BigInteger.valueOf(5));
	    response.setTipAmount(BigDecimal.valueOf(0.05).multiply(billAmount));
	} else {
	    response.setTipPercent(BigInteger.valueOf(10));
	    response.setTipAmount(BigDecimal.valueOf(0.10).multiply(billAmount));
	}
	
	return response;
    }

}
